package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: WangHongKun
 * @Date: 2022/9/22 16:58
 * @Email: 2028911483@qq.com
 * @Phone: 18683977706
 */

@RestController("UserSetmealController")
@Slf4j
@Api(tags = "套餐相关接口")
@RequestMapping("/user/setmeal")
public class SetmealController {


    @Autowired
    private SetmealService setmealService;

    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐接口")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")  //key: setmealCache::100
    public Result<List<Setmeal>> QueryByCategoryId(Long categoryId){
        log.info("查询的分类id：{}",categoryId);
        List<Setmeal> setmealList = setmealService.getByCategoryId(categoryId);
        return Result.success(setmealList);
    }

    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询包含的菜品接口")
    public Result<List<DishItemVO>>  QueryDishsBySetmealId( @PathVariable(name = "id") Long id){
        log.info("查询的套餐id：{}",id);
        List<DishItemVO> dishsBySetmealId = setmealService.getDishsBySetmealId(id);
        return Result.success(dishsBySetmealId);
    }


}
